<?php

	//get the users id
	$id = $_GET['id'];
	
	//generate the query and escape it
	$query = sprintf("SELECT * FROM CS275.files WHERE userId='%s'", mysql_real_escape_string($id));
	
	//connect to database
	$link = mysql_connect('localhost', 'root', 'admin');
	if(!$link){
		die('Could not connect: ' . mysql_error());	
	}
	
	//perform query
	$result = mysql_query($query, $link);
	
	//if it failed
	if (!$result) {
    	$message  = 'Invalid query: ' . mysql_error() . "\n";
    	$message .= 'Whole query: ' . $query;
    	die($message);
	}
	
	$stack = array();
	//if we get results
	while($row = mysql_fetch_assoc($result)){
		array_push($stack, array("id" => $row["id"], "name" => $row["name"]));
	}
	
	//free results
	mysql_free_result($result);
	
	//close link
	mysql_close($link);
	
	//output json
	echo(json_encode(array("myFiles" => $stack)));


?>